﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Bike.Forms;
using Bike.Common;
using Bike.Forms.Categories;
using Telerik.WinControls;
using Bike.Biz;
using Bike.Forms.Products;
using Bike.Forms.Warehouses;

namespace Bike
{
    public partial class BikeMain : Form
    {
        public BikeMain()
        {
            //BikeLogger.Log("Application Started");
            InitializeComponent();
            AditionalInitialize();
        }

        private void AditionalInitialize()
        {
            this.mainRibbonBar.ExitButton.Click += new EventHandler(ExitButton_Click);
        }

        void ExitButton_Click(object sender, EventArgs e)
        {
            CloseApplication(sender, e);
        }

        private void ShowChangePasswordFrom(object sender, EventArgs e)
        {
            ChangePW form = new ChangePW();
            form.ShowDialog();
        }

        private void CloseApplication(object sender, EventArgs e)
        {
            if (RadMessageBox.Show("Bạn chắc chắn muốn thoát khỏi chương trình chứ?", "Đóng ứng dụng",MessageBoxButtons.YesNo, RadMessageIcon.Info)  == System.Windows.Forms.DialogResult.Yes)
            {
                Application.Exit();
            }
            else
            {
               
            }
        }

        private void mnuAddCategory_Click(object sender, EventArgs e)
        {
            AddCategoryForm form = new AddCategoryForm();
            form.ShowDialog();
        }

        private void OnApplicationStart(object sender, EventArgs e)
        {
            DisplayProducts();
            LoadConfiguration();
        }

        private void LoadConfiguration()
        {
            ConfigService config = new ConfigService();

            SessionManager.Configuration = config.GetConfiguration();
        }

        private void DisplayProducts()
        {
            CategoryService service = new CategoryService();
            var datasource = service.GetAllItems();
            UIHelper.DisplayCategory(datasource, tvProducts);

        }

        private void ShowAddProductForm(object sender, EventArgs e)
        {
            AddProductForm form = new AddProductForm();
            form.ShowDialog();
        }

        private void radButtonElement4_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void mnuImportResellProduct_Click(object sender, EventArgs e)
        {
            WarehouseAddIemForm form = new WarehouseAddIemForm()
            {
                ImportType = 0 //Nhap san pham thuong mai.
            };
            form.ShowDialog();

        }

        private void mnuViewImports_Click(object sender, EventArgs e)
        {
            documentTabStrip1.ActiveWindow = documentWindow1;
        }

        private void radSchedulerNavigator1_MonthViewClick(object sender, EventArgs e)
        {
            RadMessageBox.Show("tét", "test");
        }

        private void radSchedulerNavigator1_DayViewClick(object sender, EventArgs e)
        {
            LoadImportOrders();
        }

        private void LoadImportOrders()
        {
            OrderService service = new OrderService();
            OrderDetailService orderdetailservice = new OrderDetailService();

            radGridView1.DataSource = service.GetAllItems();
            gridViewTemplate1.DataSource = orderdetailservice.GetAllItems();
        }
    }
}
